/**
 * 
 */
package com.primestone.cim.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.primestone.cim.util.enums.SocDevEnum;

/**
 * @author cesar.mateus
 *
 */
public class SocketOrDevice {
	private String socket = null;
	private String device = null;
	private SocDevEnum socketOrDevice = null;

	/**
	 * @param elements
	 * @param socketOrDevice
	 */
	public SocketOrDevice(String elements, SocDevEnum socketOrDevice) {
		switch (socketOrDevice) {
			case WORK_SOCKETS: {
				this.socket = elements;
				break;
			}
			
			case WORK_DEVICES: {
				this.device = elements;
				break;
			}
		}
	}


	/**
	 * @return the socket
	 */
	public String getSocket() {
		return this.socket;
	}
	/**
	 * @param socket the socket to set
	 */
	public void setSocket(String socket) {
		this.socket = socket;
	}

	/**
	 * @return
	 */
	public List<String> getSockets() {
		List<String> idSockets = new ArrayList<String>();
		if (StringUtil.safe(this.socket)) {
			// Si es una cadena de sockets se tokeniza y se construye una lista a partir de sus tokens.
			if  (this.socket.contains(StringUtil.COMMA)) {
				Scanner scanner = new Scanner(this.socket);
				scanner.useDelimiter(StringUtil.COMMA);
				while (scanner.hasNext()) {
					idSockets.add(scanner.next().trim());
				}
			} else {
				idSockets.add(this.socket);
			}
		}
		return idSockets;
	}

	/**
	 * @return the device
	 */
	public String getDevice() {
		return this.device;
	}

	/**
	 * @return
	 */
	public List<String> getDevices() {
		List<String> idDevices = new ArrayList<String>();
		if (StringUtil.safe(this.device)) {
			// Si es una cadena de devices se tokeniza y se construye una lista a partir de sus tokens.
			if  (this.device.contains(StringUtil.COMMA)) {
				Scanner scanner = new Scanner(this.device);
				scanner.useDelimiter(StringUtil.COMMA);
				while (scanner.hasNext()) {
					idDevices.add(scanner.next().trim());
				}
			} else {
				idDevices.add(this.device);
			}
		}
		return idDevices;
	}

	/**
	 * @param device the device to set
	 */
	public void setDevice(String device) {
		this.device = device;
	}
	/**
	 * @return the socketOrDevice
	 */
	public SocDevEnum getSocketOrDevice() {
		return this.socketOrDevice;
	}
	/**
	 * @param socketOrDevice the socketOrDevice to set
	 */
	public void setSocketOrDevice(SocDevEnum socketOrDevice) {
		this.socketOrDevice = socketOrDevice;
	}



}
